/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh Manish Mehta
 												
Class							:				Wargus Main Trace
 
Function						: 				The class provides a  hook to start
												Wargus along with the behavior 
												Adaptation System 
*********************************************************************************/

package base;

import java.util.LinkedList;

import mre.MRE;
import tacticalLayer.ScriptedTacticalLayer;
import tacticalLayer.TacticalLayer;
import cbr.CBR;

public class WargusmainTrace extends CBLILRModule {
	protected LinkedList<CBLILRModule> m_modules=new LinkedList<CBLILRModule>();
	protected ProxyBot m_pb;	// This allows us to read the game state from Wargus
	protected CBR m1;
	
	public WargusmainTrace(ProxyBot a_pb, CBR a_cbr) {		
		super();
		m_pb = a_pb;
		m1 = a_cbr;
	}
	public WargusmainTrace(){}
	
	public void run(){
		
		System.out.println("MAIN: Creating the Wargus CBR engine...");
				
		{
//			TacticalLayer m2=new SimpleTacticalLayer(m_pb);
			TacticalLayer m2=new ScriptedTacticalLayer(m_pb);		
			MRE m3 = null;
			try {
				m3 = new MRE(m_pb, m1,m2);
			} catch (Exception e) {
				e.printStackTrace();
			}
			m_modules.add(m1);
			m_modules.add(m2);
			m_modules.add(m3);
			
		}

		System.out.println("MAIN: Starting the Wargus CBR engine...");
		
		for(CBLILRModule m: m_modules) m.start();

		while(!m_stopSignal) {
			try {
				Thread.sleep(100);
			} catch(Exception e) {
			}
		}

		System.out.println("MAIN: Stopping the Wargus CBR engine...");

		for(CBLILRModule m: m_modules) m.stop();
		for(CBLILRModule m: m_modules) m.join();
	}
}

